﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using XMK.Tadong.Biz;
using Newtonsoft.Json;
using System.Text;
using XMK.Utils;
using XMK.Tadong.Model;
using XMK.Tadong.Web.Language;

namespace XMK.Tadong.Web.SpaceClassView
{
    public partial class ClassFileHandler: FileExplorerPage
    {
        private string personId = "48f3889c-af8d-401f-ada2-c383031af92d1";
        private string teamId = "16";
        protected void Page_Load(object sender, EventArgs e)
        {
            string currrentForldId = Request.Params.Get("forldId");//当前文件夹Id
            string currentClassType = Request.Params.Get("classType");//当前分类类别
            string spaceType = Request.Params.Get("spaceType");//空间类别10-个人空间，20-课题组空间，30-项目库空间
            teamId = Request.Params.Get("teamId");//课题组id
            personId = Request.Params.Get("userId");
            DataTable dt_data = null;
            string resultJson = "";
            switch (currentClassType)
            {
                case "CREATE_TIME": { resultJson = getDataByTime(currrentForldId, spaceType, currentClassType); break; }
                case "FILE_SIZE": { resultJson = getDataByByte(currrentForldId, spaceType, currentClassType); break; }
                case "DEST_OBJ": { resultJson = getDataByObj(currrentForldId, spaceType, currentClassType); break; }
                case "BIZ_OBJ": { resultJson = getDataByBiz(currrentForldId, spaceType, currentClassType); break; }
                case "FILE_EXT": { resultJson = getDataByType(currrentForldId, spaceType, currentClassType); break; }

            }
            Response.ContentType = "text/json";
            Response.Write(resultJson);
            Response.End();

        }
        //根据时间分类
        public string getDataByTime(string currrentForldId, string spaceType, string classType)
        {
            DataTable dt_groupStandard = new DataTable();
            dt_groupStandard.Columns.Add("minid", Type.GetType("System.String")); //同类中最小id
            dt_groupStandard.Columns.Add("groupItem", Type.GetType("System.String")); //分类条件
            dt_groupStandard.Columns.Add("groupName", Type.GetType("System.String")); //类别名
            dt_groupStandard.Columns.Add("number", Type.GetType("System.Int32")); //个数
            //初始化dt_groupStandard表
            DataRow newRow1 = dt_groupStandard.NewRow();
            newRow1["groupItem"] = "week";
            newRow1["groupName"] = lang.Get("week");
            newRow1["number"] = 0;
            dt_groupStandard.Rows.Add(newRow1);
            //当年月份
            int year = DateTime.Now.Year;//年份
            int month = DateTime.Now.Month;//月份
            for (int i = month; i > 0; i--)
            {
                DataRow newRow = dt_groupStandard.NewRow();
                newRow["groupItem"] = year.ToString() + "/" + i.ToString();
                newRow["groupName"] = year.ToString() + "/" + i.ToString();
                newRow["number"] = 0;
                dt_groupStandard.Rows.Add(newRow);
            }
            DataRow newRow2 = dt_groupStandard.NewRow();
            newRow2["groupItem"] = (year - 1).ToString();
            newRow2["groupName"] = (year - 1).ToString();
            newRow2["number"] = 0;
            dt_groupStandard.Rows.Add(newRow2);
            DataRow newRow3 = dt_groupStandard.NewRow();
            newRow3["groupItem"] = "early";
            newRow3["groupName"] = lang.Get("early");
            newRow3["number"] = 0;
            dt_groupStandard.Rows.Add(newRow3);
            DataTable dt = null;

            Tb_SpaceBiz biz = new Tb_SpaceBiz();
            string sqlwhere;

            for (int i = 0; i < dt_groupStandard.Rows.Count; i++)
            {
                if (dt_groupStandard.Rows[i]["groupItem"].ToString() == "week")
                {//本周
                    sqlwhere = "trunc(sysdate)-trunc(create_time)>0 and  trunc(sysdate)-trunc(create_time)<7 and folder_id=" + currrentForldId + "";
                }

                else if (dt_groupStandard.Rows[i]["groupItem"].ToString() == DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString())
                { //本月
                    sqlwhere = " create_time >=TRUNC(SYSDATE, 'MM') and create_time<=last_day(SYSDATE) and folder_id=" + currrentForldId + "";
                }

                else if (dt_groupStandard.Rows[i]["groupItem"].ToString() == (DateTime.Now.Year - 1).ToString())
                { //去年
                    sqlwhere = "create_time>=add_months(trunc(sysdate, 'yyyy'), -12)  and  create_time<=add_months(trunc(sysdate, 'yyyy'), 0)-1 and folder_id=" + currrentForldId + "";
                }

                else if (dt_groupStandard.Rows[i]["groupItem"].ToString() == "early")
                { //更早
                    sqlwhere = "create_time<add_months(trunc(sysdate, 'yyyy'), -12)  and folder_id=" + currrentForldId + "";
                }

                else
                { //本年前几个月

                    sqlwhere = " create_time<last_day(to_date('" + dt_groupStandard.Rows[i]["groupItem"].ToString() + "','yyyy/mm'))+1 and create_time>trunc(to_date('" + dt_groupStandard.Rows[i]["groupItem"].ToString() + "','yyyy/mm')) and folder_id=" + currrentForldId + "";
                }
                dt = biz.getXmkClassDetailFile(personId, teamId, sqlwhere, spaceType);
                if (dt.Rows.Count != 0)
                {
                    dt_groupStandard.Rows[i]["minid"] = dt.Rows[0]["ID"].ToString();
                    dt_groupStandard.Rows[i]["number"] = dt.Rows.Count;
                }


            }
            //清除没有数据的行
            for (int i = 0; i < dt_groupStandard.Rows.Count; i++)
            {
                if (dt_groupStandard.Rows[i]["number"].ToString() == "0")
                {
                    dt_groupStandard.Rows.RemoveAt(i);
                    i--;

                }
            }
            return JsonHelper.ToJson(dt_groupStandard);
        }
        //根据文件大小分类    
        public string getDataByByte(string currrentForldId, string spaceType, string classType)
        {
            DataTable dt_groupStandard = new DataTable();
            dt_groupStandard.Columns.Add("minid", Type.GetType("System.String")); //同类中最小id
            dt_groupStandard.Columns.Add("groupItem", Type.GetType("System.String")); //分类条件
            dt_groupStandard.Columns.Add("groupName", Type.GetType("System.String")); //类别名
            dt_groupStandard.Columns.Add("number", Type.GetType("System.Int32")); //个数
            //初始化dt_groupStandard表
            DataRow newRow1 = dt_groupStandard.NewRow();
            newRow1["groupItem"] = "1k-1m";
            newRow1["groupName"] = lang.Get("SmallFile");
            newRow1["number"] = 0;
            dt_groupStandard.Rows.Add(newRow1);
            DataRow newRow2 = dt_groupStandard.NewRow();
            newRow2["groupItem"] = "1m-2m";
            newRow2["groupName"] = "1MB";
            newRow2["number"] = 0;
            dt_groupStandard.Rows.Add(newRow2);
            DataRow newRow3 = dt_groupStandard.NewRow();
            newRow3["groupItem"] = "2m-3m";
            newRow3["groupName"] = "2M";
            newRow3["number"] = 0;
            dt_groupStandard.Rows.Add(newRow3);
            DataRow newRow4 = dt_groupStandard.NewRow();
            newRow4["groupItem"] = "3m-4m";
            newRow4["groupName"] = "3M";
            newRow4["number"] = 0;
            dt_groupStandard.Rows.Add(newRow4);
            DataRow newRow5 = dt_groupStandard.NewRow();
            newRow5["groupItem"] = "4m-5m";
            newRow5["groupName"] = "4M";
            newRow5["number"] = 0;
            dt_groupStandard.Rows.Add(newRow5);
            DataRow newRow6 = dt_groupStandard.NewRow();
            newRow6["groupItem"] = "5m-10m";
            newRow6["groupName"] = "5M~10M";
            newRow6["number"] = 0;
            dt_groupStandard.Rows.Add(newRow6);
            DataRow newRow7 = dt_groupStandard.NewRow();
            newRow7["groupItem"] = "10m-20m";
            newRow7["groupName"] = "10MB~20MB";
            newRow7["number"] = 0;
            dt_groupStandard.Rows.Add(newRow7);
            DataRow newRow8 = dt_groupStandard.NewRow();
            newRow8["groupItem"] = "20m-50m";
            newRow8["groupName"] = "20~50MB";
            newRow8["number"] = 0;
            dt_groupStandard.Rows.Add(newRow8);
            DataRow newRow9 = dt_groupStandard.NewRow();
            newRow9["groupItem"] = "50m-*";
            newRow9["groupName"] = lang.Get("LargeFile");
            newRow9["number"] = 0;
            dt_groupStandard.Rows.Add(newRow9);

            DataTable dt = null;
            Tb_SpaceBiz biz = new Tb_SpaceBiz();
            dt = biz.getXmkClassFlie(personId, teamId, currrentForldId, classType, spaceType);

            //绑定dt_groupStandard
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (!Convert.IsDBNull(dt.Rows[i]["FILE_SIZE"]))
                {
                    string file_size = dt.Rows[i]["FILE_SIZE"].ToString().Trim().ToLower();
                    if (file_size.Contains('m'))
                    {
                        file_size = file_size.Replace("mb", "");
                        file_size = file_size.Replace('m', ' ');
                        if ((Convert.ToInt32(file_size) > 1 || Convert.ToInt32(file_size) == 1) && (Convert.ToInt32(file_size) < 2))
                        {
                            if (dt_groupStandard.Rows[1]["minid"].ToString() == "")
                            {
                                dt_groupStandard.Rows[1]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                            }
                            dt_groupStandard.Rows[1]["number"] = Convert.ToInt32(dt_groupStandard.Rows[1]["number"]) + 1;
                        }
                        else if ((Convert.ToInt32(file_size) > 2 || Convert.ToInt32(file_size) == 2) && (Convert.ToInt32(file_size) < 3))
                        {
                            if (dt_groupStandard.Rows[2]["minid"].ToString() == "")
                            {
                                dt_groupStandard.Rows[2]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                            }
                            dt_groupStandard.Rows[2]["number"] = Convert.ToInt32(dt_groupStandard.Rows[2]["number"]) + 1;
                        }
                        else if ((Convert.ToInt32(file_size) > 3 || Convert.ToInt32(file_size) == 3) && (Convert.ToInt32(file_size) < 4))
                        {
                            if (dt_groupStandard.Rows[3]["minid"].ToString() == "")
                            {
                                dt_groupStandard.Rows[3]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                            }
                            dt_groupStandard.Rows[3]["number"] = Convert.ToInt32(dt_groupStandard.Rows[3]["number"]) + 1;
                        }
                        else if ((Convert.ToInt32(file_size) > 4 || Convert.ToInt32(file_size) == 4) && (Convert.ToInt32(file_size) < 5))
                        {
                            if (dt_groupStandard.Rows[4]["minid"].ToString() == "")
                            {
                                dt_groupStandard.Rows[4]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                            }
                            dt_groupStandard.Rows[4]["number"] = Convert.ToInt32(dt_groupStandard.Rows[4]["number"]) + 1;
                        }
                        else if ((Convert.ToInt32(file_size) > 5 || Convert.ToInt32(file_size) == 5) && (Convert.ToInt32(file_size) < 10))
                        {
                            if (dt_groupStandard.Rows[5]["minid"].ToString() == "")
                            {
                                dt_groupStandard.Rows[5]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                            }
                            dt_groupStandard.Rows[5]["number"] = Convert.ToInt32(dt_groupStandard.Rows[5]["number"]) + 1;
                        }
                        else if ((Convert.ToInt32(file_size) > 10 || Convert.ToInt32(file_size) == 10) && (Convert.ToInt32(file_size) < 20))
                        {
                            if (dt_groupStandard.Rows[6]["minid"].ToString() == "")
                            {
                                dt_groupStandard.Rows[6]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                            }
                            dt_groupStandard.Rows[6]["number"] = Convert.ToInt32(dt_groupStandard.Rows[6]["number"]) + 1;
                        }
                        else if ((Convert.ToInt32(file_size) > 20 || Convert.ToInt32(file_size) == 20) && (Convert.ToInt32(file_size) < 50))
                        {
                            if (dt_groupStandard.Rows[7]["minid"].ToString() == "")
                            {
                                dt_groupStandard.Rows[7]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                            }
                            dt_groupStandard.Rows[7]["number"] = Convert.ToInt32(dt_groupStandard.Rows[7]["number"]) + 1;
                        }
                        else if (Convert.ToInt32(file_size) > 50 || Convert.ToInt32(file_size) == 50)
                        {
                            if (dt_groupStandard.Rows[8]["minid"].ToString() == "")
                            {
                                dt_groupStandard.Rows[8]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                            }
                            dt_groupStandard.Rows[8]["number"] = Convert.ToInt32(dt_groupStandard.Rows[8]["number"]) + 1;
                        }

                    }
                    else if (file_size.Contains('k'))
                    {
                        if (dt_groupStandard.Rows[0]["minid"].ToString() == "")
                        {
                            dt_groupStandard.Rows[0]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                        }
                        dt_groupStandard.Rows[0]["number"] = Convert.ToInt32(dt_groupStandard.Rows[0]["number"]) + 1;
                    }
                }
            }
            //清除没有数据的行
            for (int i = 0; i < dt_groupStandard.Rows.Count; i++)
            {
                if (dt_groupStandard.Rows[i]["number"].ToString() == "0")
                {
                    dt_groupStandard.Rows.RemoveAt(i);
                    i--;

                }
            }
            return JsonHelper.ToJson(dt_groupStandard);

        }
        //根据目标分类
        public string getDataByObj(string currrentForldId, string spaceType, string classType)
        {
            DataTable dt_groupStandard = new DataTable();
            dt_groupStandard.Columns.Add("minid", Type.GetType("System.String")); //同类中最小id
            dt_groupStandard.Columns.Add("groupItem", Type.GetType("System.String")); //分类条件
            dt_groupStandard.Columns.Add("groupName", Type.GetType("System.String")); //类别名
            dt_groupStandard.Columns.Add("number", Type.GetType("System.Int32")); //个数

            //获的文件信息列表
            DataTable dt = null;
            Tb_SpaceBiz biz = new Tb_SpaceBiz();
            dt = biz.getXmkClassFlie(personId, teamId, currrentForldId, classType, spaceType);

            //初始化dt_groupStandard表
            DataRow newRow1 = dt_groupStandard.NewRow();
            newRow1["groupItem"] = "other";
            newRow1["groupName"] = lang.Get("Other");
            newRow1["number"] = 0;
            dt_groupStandard.Rows.Add(newRow1);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string objstr = dt.Rows[i]["DEST_OBJ"].ToString();
                if (objstr == "")
                {
                    if (dt_groupStandard.Rows[0]["minid"].ToString() == "")
                    {
                        dt_groupStandard.Rows[0]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                    }
                    dt_groupStandard.Rows[0]["number"] = Convert.ToInt32(dt_groupStandard.Rows[0]["number"]) + 1;
                }
                else
                {
                    string[] objstrArr = objstr.Split(' ');
                    for (int n = 0; n < objstrArr.Length; n++)
                    {
                        int countNum = isExstItem(objstrArr[n].ToString(), dt_groupStandard);
                        if (countNum == -1)
                        {
                            //当前没有初始化该分类
                            DataRow newRow = dt_groupStandard.NewRow();
                            newRow["groupItem"] = objstrArr[n].ToString();
                            newRow["groupName"] = objstrArr[n].ToString();
                            newRow["number"] = 1;
                            dt_groupStandard.Rows.Add(newRow);
                            dt_groupStandard.Rows[dt_groupStandard.Rows.Count - 1]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                        }
                        else
                        {
                            //已经存在分类
                            if (dt_groupStandard.Rows[countNum]["minid"].ToString() == "")
                            {
                                dt_groupStandard.Rows[countNum]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                            }
                            dt_groupStandard.Rows[countNum]["number"] = Convert.ToInt32(dt_groupStandard.Rows[countNum]["number"]) + 1;
                        }
                    }
                }
            }

            //清除没有数据的行
            for (int i = 0; i < dt_groupStandard.Rows.Count; i++)
            {
                if (dt_groupStandard.Rows[i]["number"].ToString() == "0")
                {
                    dt_groupStandard.Rows.RemoveAt(i);
                    i--;

                }
            }
            return JsonHelper.ToJson(dt_groupStandard);
        }
        //根据业务分类
        public string getDataByBiz(string currrentForldId, string spaceType, string classType)
        {
            DataTable dt_groupStandard = new DataTable();
            dt_groupStandard.Columns.Add("minid", Type.GetType("System.String")); //同类中最小id
            dt_groupStandard.Columns.Add("groupItem", Type.GetType("System.String")); //分类条件
            dt_groupStandard.Columns.Add("groupName", Type.GetType("System.String")); //类别名
            dt_groupStandard.Columns.Add("number", Type.GetType("System.Int32")); //个数

            //获的文件信息列表
            DataTable dt = null;
            Tb_SpaceBiz biz = new Tb_SpaceBiz();
            dt = biz.getXmkClassFlie(personId, teamId, currrentForldId, classType, spaceType);
            //初始化dt_groupStandard表
            DataRow newRow1 = dt_groupStandard.NewRow();
            newRow1["groupItem"] = "other";
            newRow1["groupName"] = lang.Get("Other");
            newRow1["number"] = 0;
            dt_groupStandard.Rows.Add(newRow1);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string objstr = dt.Rows[i]["BIZ_OBJ"].ToString();
                if (objstr == "")
                {
                    if (dt_groupStandard.Rows[0]["minid"].ToString() == "")
                    {
                        dt_groupStandard.Rows[0]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                    }
                    dt_groupStandard.Rows[0]["number"] = Convert.ToInt32(dt_groupStandard.Rows[0]["number"]) + 1;
                }
                else
                {
                    string[] objstrArr = objstr.Split(' ');
                    for (int n = 0; n < objstrArr.Length; n++)
                    {
                        int countNum = isExstItem(objstrArr[n].ToString(), dt_groupStandard);
                        if (countNum == -1)
                        {
                            //当前没有初始化该分类
                            DataRow newRow = dt_groupStandard.NewRow();
                            newRow["groupItem"] = objstrArr[n].ToString();
                            newRow["groupName"] = objstrArr[n].ToString();
                            newRow["number"] = 1;
                            dt_groupStandard.Rows.Add(newRow);
                            dt_groupStandard.Rows[dt_groupStandard.Rows.Count - 1]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                        }
                        else
                        {
                            //已经存在分类
                            if (dt_groupStandard.Rows[countNum]["minid"].ToString() == "")
                            {
                                dt_groupStandard.Rows[countNum]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                            }
                            dt_groupStandard.Rows[countNum]["number"] = Convert.ToInt32(dt_groupStandard.Rows[countNum]["number"]) + 1;
                        }
                    }
                }
            }

            //清除没有数据的行
            for (int i = 0; i < dt_groupStandard.Rows.Count; i++)
            {
                if (dt_groupStandard.Rows[i]["number"].ToString() == "0")
                {
                    dt_groupStandard.Rows.RemoveAt(i);
                    i--;

                }
            }
            return JsonHelper.ToJson(dt_groupStandard);
        }
        //根据文件格式分类
        public string getDataByType(string currrentForldId, string spaceType, string classType)
        {
            DataTable dt_groupStandard = new DataTable();
            dt_groupStandard.Columns.Add("minid", Type.GetType("System.String")); //同类中最小id
            dt_groupStandard.Columns.Add("groupItem", Type.GetType("System.String")); //分类条件
            dt_groupStandard.Columns.Add("groupName", Type.GetType("System.String")); //类别名
            dt_groupStandard.Columns.Add("number", Type.GetType("System.Int32")); //个数
            //初始化dt_groupStandard表
            EXTBiz extbiz = new EXTBiz();
            DataTable dt_ext = extbiz.QueryExtList();
            for (int i = 0; i < dt_ext.Rows.Count; i++)
            {
                if (dt_ext.Rows[i][0].ToString() != "unknow")
                {
                    DataRow newRow = dt_groupStandard.NewRow();
                    newRow["groupItem"] = dt_ext.Rows[i][0].ToString();
                    newRow["groupName"] = dt_ext.Rows[i][0].ToString();
                    newRow["number"] = 0;
                    dt_groupStandard.Rows.Add(newRow);
                }
            }

            //获的文件信息列表
            DataTable dt = null;
            Tb_SpaceBiz biz = new Tb_SpaceBiz();
            dt = biz.getXmkClassFlie(personId, teamId, currrentForldId, classType, spaceType);
            //绑定dt_groupStandard
            ExtTypeinfo extcode = null;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                extcode = extbiz.getExtCodeByExtent(dt.Rows[i]["FILE_EXT"].ToString());
                if (extcode != null)
                {
                    for (int j = 0; j < dt_groupStandard.Rows.Count; j++)
                    {
                        if (extcode.EXT_CODE == dt_groupStandard.Rows[j]["groupItem"].ToString())
                        {
                            if (dt_groupStandard.Rows[j]["minid"].ToString() == "")
                            {
                                dt_groupStandard.Rows[j]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                            }
                            dt_groupStandard.Rows[j]["number"] = Convert.ToInt32(dt_groupStandard.Rows[j]["number"]) + 1;
                        }
                    }

                }
                else
                {
                    int countNum = isExstItem(dt.Rows[i]["FILE_EXT"].ToString(), dt_groupStandard);
                    if (countNum != -1)
                    {
                        //已经存在当前分类
                        if (dt_groupStandard.Rows[countNum]["minid"].ToString() == "")
                        {
                            dt_groupStandard.Rows[countNum]["minid"] = dt.Rows[i]["FILE_ID"].ToString();
                        }
                        dt_groupStandard.Rows[countNum]["number"] = Convert.ToInt32(dt_groupStandard.Rows[countNum]["number"]) + 1;

                    }
                    else
                    {
                        //当前没有初始化该分类
                        DataRow newRow = dt_groupStandard.NewRow();
                        newRow["groupItem"] = dt.Rows[i]["FILE_EXT"].ToString();
                        newRow["groupName"] = dt.Rows[i]["FILE_EXT"].ToString();
                        newRow["number"] = 1;
                        dt_groupStandard.Rows.Add(newRow);

                        dt_groupStandard.Rows[dt_groupStandard.Rows.Count - 1]["minid"] = dt.Rows[i]["FILE_ID"].ToString();


                    }
                }
            }
            //清除没有数据的行
            for (int i = 0; i < dt_groupStandard.Rows.Count; i++)
            {
                if (dt_groupStandard.Rows[i]["number"].ToString() == "0")
                {
                    dt_groupStandard.Rows.RemoveAt(i);
                    i--;

                }
            }
            return JsonHelper.ToJson(dt_groupStandard);
        }

        //判断是否已存在当前分类
        public int isExstItem(string currItem, DataTable dt_groupStandard)
        {
            for (int i = 0; i < dt_groupStandard.Rows.Count; i++)
            {
                if (currItem == (dt_groupStandard.Rows[i]["groupItem"].ToString()))
                {
                    return i;
                }
            }
            return -1;
        }

        /// <summary>
        /// 计算两个日期的时间间隔
        /// </summary>
        /// <param name="DateTime1">第一个日期和时间</param>
        /// <param name="DateTime2">第二个日期和时间</param>
        /// <returns></returns>
        public TimeSpan DateDiff(DateTime DateTime1, DateTime DateTime2)
        {
            string dateDiff = null;

            TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
            TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
            TimeSpan ts = ts1.Subtract(ts2).Duration();


            return ts;
        }

    }
}